{include file="publics/head"/}


<body class="no-skin">
{include file="publics/header"/}
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    {include file="publics/sidebar"/}
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            {include file="publics/breadcrumbs"/}

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                {include file="publics/set"/}

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form class="form-horizontal"  id="form" action="{:url('add_auto_reply')}" method="post">
                            <input type="hidden" name="type" id="type" value="{$type}">
                            <input type="hidden" name="id" id="id" value="{$reply.id}">
                            {if condition="$type eq 'keyword'"}
                                <div class="form-group">
                                    <label class="col-sm-1 control-label no-padding-right" for="form-field-2">
                                        规则 </label>
                                    <div class="col-sm-9">
                                        <input type="text" name="rule" id="rule" placeholder="规则"
                                               class="col-xs-10 col-sm-5" value="{$wxmenu.rule}">
                                        <span class="help-inline col-xs-12 col-sm-7">
                                                    <span class="middle">最多32个字</span>
                                                </span>
                                    </div>
                                </div>
                                <div class="space-4"></div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label no-padding-right" for="keywords">
                                        关键词 </label>
                                    <div class="col-sm-9">
                                        <input type="text" name="keywords" id="keywords" placeholder="关键词"
                                               class="col-xs-10 col-sm-5" value="{$wxmenu.rule}">
                                        <span class="help-inline col-xs-12 col-sm-7">
                                                    <span class="middle">多个关键字，请以英文逗号隔开(',')</span>
                                                </span>
                                    </div>
                                </div>
                            {/if}
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-2"> 类型 </label>
                                <div class="col-sm-9">
                                    <select id="msg_type" name="msg_type" class="rcol-xs-10 col-sm-5">
                                        <option value="text" {if condition="$reply.msg_type=='text'"}selected="selected"{/if}>文本</option>
                                        <option value="news" {if condition="$reply.msg_type=='news'"}selected="selected"{/if}>图文</option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="description"> 回复内容 </label>
                                <div class="col-sm-9">
                                    <textarea name="content" id="content" placeholder="回复内容"
                                              class="col-xs-10 col-sm-5"
                                              rows="5">{$reply.data}</textarea>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">回复内容。</span>
											</span>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="col-md-offset-2 col-md-9">
                                <button class="btn btn-info submit" type="button">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="icon-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>
                        </form>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    {include file="publics/footer"/}

</div><!-- /.main-container -->

{include file="publics/footerjs"/}
<!-- inline scripts related to this page -->

<script type="text/javascript">
    $(function () {
        $(".submit").click(function () {
            if ("{$type}" != "keyword"){
                var jsonData = {
                    'type' : $("#type").val(),
                    'msg_type' : $("select[name='msg_type']").val(),
                    'content' : $("#content").val()
                }
            }else{
                var jsonData = {
                    'rule' : $("#rule").val(),
                    'keywords' : $("#keywords").val(),
                    'type' : $("#type").val(),
                    'msg_type' : $("select[name='msg_type']").val(),
                    'content' : $("#content").val()
                }
            }
            var postUrl = "{:url('add_auto_reply')}"
            var id = $("#id").val();
            if(id){
                postUrl = "{:url('update_auto_reply')}"
                postUrl = postUrl + '?id='+id
            }
            console.log(jsonData)
            $.ajax({
                type: "post",
                url: postUrl,
                dataType: 'JSON',
                data: jsonData,
                error: function () {
                    return false;
                },
                success: function (data) {
                    bootbox.alert({
                        buttons: {
                            ok: {label: '确定',className: 'btn-danger'}
                        },
                        message: data.message,
                        callback: function() {
                            location.reload();
                        },
                        title: "系统提示",
                    });
                }
            });

        })

    })
</script>

</body>
</html>
